﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DisplayBoardInfo.Server.Forms.CustomComponents.EntityList
{
    public partial class EntityList : UserControl
    {
        private IEnumerable<Entities.Entity> items;
        private ListModel listModel;

        public EntityList()
        {
            InitializeComponent();
        }

        public IEnumerable<Entities.Entity> Items
        {
            get
            {
                return items;
            }

            set
            {
                items = value;
                if (items != null)
                {
                    listModel = ListModelFactory.Create(value);
                    RefreshView();
                }
            }
        }

        public void RefreshView()
        {
            listView.Clear();
            foreach (string item in listModel.GetHeader())
            {
                listView.Columns.Add(item);
            }

            string[,] data = listModel.GetData();

            for (int i = 0; i < data.GetLength(0); i++)
            {
                ListViewItem listItem = new ListViewItem();
                listItem.Text = data[i, 0];
                for (int j = 1; j < data.GetLength(1); j++)
                {
                    listItem.SubItems.Add(data[i, j]);
                }
                listView.Items.Add(listItem);
            }
        }
    }
}
